package com.exhibition.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.exhibition.service.ITbHostService;
import com.exhibition.util.Util;

@Controller
public class TbHostController {
	
	@Autowired
	ITbHostService tbHostService;
	
	@RequestMapping("host/hostInfo.do")	
	public ModelAndView hostInfo(HttpServletRequest request){
		ModelAndView mav=new ModelAndView("./myinfo/info.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("host_account", request.getSession().getAttribute("account"));
		mav.addObject("host", tbHostService.getOne(map));
		return mav;
	}
	@RequestMapping("host/hostInfoOk.do")	
	public ModelAndView hostInfoOk(HttpServletRequest request,
			  String host_id,
		      String host_name,
			  String host_pwd){
		ModelAndView mav=new ModelAndView("redirect:/host/hostInfo.do");
		Map<String,Object> map=new HashMap<String,Object>();
		 map.put("host_id",host_id);
		  map.put("host_name",host_name);
		  map.put("host_pwd",host_pwd);
		  tbHostService.update(map);
		return mav;
	}
	@RequestMapping("admin/hostList.do")	
	public ModelAndView list(HttpServletRequest request,String host_name){
		ModelAndView mav=new ModelAndView("./tbhost/list.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("host_name", host_name);
		mav.addObject("list", tbHostService.getList(map));
		mav.addObject("host_name", host_name);
		return mav;
	}
	@RequestMapping("admin/hostAddOk.do")	
	public ModelAndView addOk(HttpServletRequest request,
				  String host_id,
			      String host_name,
			      String host_account,
				  String host_pwd
				  ){
		ModelAndView mav=new ModelAndView("redirect:/admin/hostList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		  map.put("host_id",Util.getPrimaryKey());
		  map.put("host_name",host_name);
		  map.put("host_account",host_account);
		  map.put("host_pwd",host_pwd);
		  tbHostService.add(map);
		return mav;
	}
	@RequestMapping("admin/hostUpdate.do")	
	public ModelAndView update(HttpServletRequest request,String host_id){
		ModelAndView mav=new ModelAndView("./tbhost/update.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("host_id", host_id);
		mav.addObject("host", tbHostService.getOne(map));
		return mav;
	}
	@RequestMapping("admin/hostUpdateOk.do")	
	public ModelAndView updateOk(HttpServletRequest request,
				  String host_id,
			      String host_name,
			      String host_account,
				  String host_pwd
				  ){
		ModelAndView mav=new ModelAndView("redirect:/admin/hostList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		  map.put("host_id",host_id);
		  map.put("host_name",host_name);
		  map.put("host_account",host_account);
		  map.put("host_pwd",host_pwd);
		  tbHostService.update(map);
		return mav;
	}
	@RequestMapping("admin/hostDelete.do")	
	public ModelAndView delete(HttpServletRequest request,String host_id){
		ModelAndView mav=new ModelAndView("redirect:/admin/hostList.do");
		tbHostService.delete(host_id);
		return mav;
	}
}
